﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebSEClassLibrary;

namespace WebSE
{
    public partial class Act2 : System.Web.UI.Page
    {
        private ActPage actPage;

        protected void Page_Load(object sender, EventArgs e)
        {
            actPage = (ActPage)Session["currentPage"];
            problem.Text = actPage.Problem;
            chA.Text = actPage.Choices[0];
            chB.Text = actPage.Choices[1];
            chC.Text = actPage.Choices[2];
            chD.Text = actPage.Choices[3];

            //用户答案
            if (!Page.IsPostBack)
            {
                for (int i = 0; i < actPage.CountChsAns; i++)
                {
                    if (actPage.UserChsAns == null) break;
                    switch(actPage.UserChsAns[i])
                    {
                        case 0:
                            chA.Checked = true;
                            break;
                        case 1:
                            chB.Checked = true;
                            break;
                        case 2:
                            chC.Checked = true;
                            break;
                        case 3:
                            chD.Checked = true;
                            break;
                    }
                }
            }
        }

        //提交
        protected void submit(object sender, EventArgs e)
        {
            explain.Text = "";
            int count = 0;
            //提交时记录用户答案
            if (chA.Checked)
            {
                actPage.UserChsAns[count++] = 0;
                explain.Text += actPage.ExplainChs[0];
                explain.Text += "<br/>";
            }
            if (chB.Checked)
            {
                actPage.UserChsAns[count++] = 1;
                explain.Text += actPage.ExplainChs[1];
                explain.Text += "<br/>";
            }
            if (chC.Checked)
            {
                actPage.UserChsAns[count++] = 2;
                explain.Text += actPage.ExplainChs[2];
                explain.Text += "<br/>";
            }
            if (chD.Checked)
            {
                actPage.UserChsAns[count++] = 3;
                explain.Text += actPage.ExplainChs[3];
                explain.Text += "<br/>";
            }
            if (!chA.Checked && !chB.Checked && !chC.Checked && !chD.Checked) explain.Text = "请选择答案";
        }

        //查看答案
        protected void check(object sender, EventArgs e)
        {
            explain.Text = "";
            for (int i = 0; i < actPage.CountChsAns; i++)
            {
                explain.Text += actPage.ExplainChs[actPage.ChsAns[i]];
                explain.Text += "<br/>";
            }
        }
    }
}
